package com.medical.app.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.medical.app.common.dto.DoctorDto;
import com.medical.app.entity.OutpatientsTemplate;
import com.medical.app.entity.Subscribe;
import com.medical.app.mapper.DoctorAllMapper;
import com.medical.app.mapper.OutpatientsTemplateMapper;
import com.medical.app.mapper.SubscribeMapper;
import com.medical.app.service.DoctorService;
import com.qf.medical.ex.ServiceException;
import com.qf.medical.response.ResponseCode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/*
 * @Date : 2024/4/30 下午2:23
 * @Created by Lang
 * @ProjectName : medical-appointment-registration
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Resource
    private DoctorAllMapper doctorAllMapper;
    @Resource
    private SubscribeMapper subscribeMapper;
    @Resource
    private OutpatientsTemplateMapper outpatientsTemplateMapper;

    @Override
    public List<DoctorDto> listByDepartmentId(Long departmentId) {
        return doctorAllMapper.listByDepartmentId(departmentId);
    }

    @Transactional(rollbackFor = RuntimeException.class,timeout = 5)
    @Override
    public OutpatientsTemplate listResidue(Long doctorId) {

        LambdaQueryWrapper<OutpatientsTemplate> eq = new LambdaQueryWrapper<OutpatientsTemplate>().eq(OutpatientsTemplate::getDoctorId, doctorId);
        return outpatientsTemplateMapper.selectOne(eq);
        // //查询预约信息表有多少条关于该医生的记录
        // LambdaQueryWrapper<Subscribe> eq = new LambdaQueryWrapper<Subscribe>()
        //         .eq(Subscribe::getDoctorId, doctorId)
        //         .eq(Subscribe::getSubscribeTime, DateUtil.today());
        // Long alreadyCount = subscribeMapper.selectCount(eq);
        //
        // //比对该医生的预约记录
        // LambdaQueryWrapper<OutpatientsTemplate> eq1 = new LambdaQueryWrapper<OutpatientsTemplate>().eq(OutpatientsTemplate::getDoctorId, doctorId);
        // Long count  = outpatientsTemplateMapper.selectCount(eq1);
        //
        // if (alreadyCount >= count){
        //     throw new ServiceException(ResponseCode.SUBSCRIBE_ALREADY_NOT_COUNT);
        // }

        //判断还有多少个号


        //赋值

        //返回
    }
}
